package com.itboye.lottery.activity.user

import android.content.Intent
import android.view.View
import android.widget.RelativeLayout
import android.widget.TextView
import com.itboye.lottery.R
import com.itboye.lottery.activity.LoginActivity
import com.itboye.lottery.alert.ByAlert
import com.itboye.lottery.app.MyApplication
import com.itboye.lottery.base.BaseActivity
import com.itboye.lottery.utils.Const
import com.itboye.lottery.utils.SPUtils
import com.itboye.lottery.utils.notifycation.NotifycationCheck.goToChangeNotifycationEnable
import com.itboye.lottery.utils.notifycation.NotifycationCheck.isOpenNotifycation
import kotlinx.android.synthetic.main.activity_set.*

class SetActivity : BaseActivity() {

    var rl_logout: TextView? = null
    var tv_clear_cache: TextView? = null
    var rl_push: RelativeLayout? = null
    override fun getLayoutId(): Int {
        return R.layout.activity_set
    }

    override fun initData() {
    }

    override fun onClick(p0: View?) {
        when (p0!!.id) {
            R.id.rl_logout -> {
                SPUtils.put(this, null, Const.UID, "")
                SPUtils.put(this, null, Const.TOKEN, "")
                SPUtils.put(this, null, Const.USER_HEAD, "")
                SPUtils.put(this, null, Const.NICKNAME, "")
                MyApplication.instance!!.removeAllActivity()
                startActivity(Intent(this, LoginActivity::class.java))
                finish()
            }
            R.id.tv_clear_cache -> {
                ByAlert.alert("清除缓存成功")
            }
            R.id.rl_push -> {
                goToChangeNotifycationEnable(this)
            }
            else -> {
            }
        }
    }

    override fun onResume() {
        super.onResume()
        var isOpen = isOpenNotifycation()
        when (isOpen) {
            true -> {
                img_push.setBackgroundResource(R.mipmap.tongzhikai)
            }
            else -> {
                img_push.setBackgroundResource(R.mipmap.tongzhiguan)
            }
        }
    }

}
